package com.gosophia.conference.action.scheme;

import java.text.SimpleDateFormat;
import java.util.List;

import net.sf.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.conferenceManagement.scheme.dto.SchemeJobDataDTO;
import com.gosophia.conferenceManagement.scheme.ws.ConferenceSchemeWebService;
import com.gosophia.oa.action.JudgeCurrentUndertaker;
import com.gosophia.taskManagement.dto.JobDTO;
import com.gosophia.taskManagement.dto.MissionDTO;
import com.gosophia.taskManagement.ws.TaskManagementWebService;
import com.gosophia.userManagement.dto.UserInfoDTO;
import com.gosophia.userManagement.ws.UserManagementWebService;

/**
 * 处理方案Action，此Action用于刷方案审批、修改、取回、定稿页面
 * @author mayue
 *
 */
@SuppressWarnings("serial")
@Scope("prototype")
@Controller("DealSchemeAction")
public class DealSchemeAction  extends BaseSupportAction{
	
	private Long jobId;
	
	private String onlinePath;
	
	private String onlineVersion;
	
	//会议上一Job的业务数据
	private SchemeJobDataDTO preSchemeJobDataDTO;
	
	//当前Job的jobType
	private String nowJobType;
	
	//获取批示人列表
	private String userInfoString;
	
	private MissionDTO missionDTO;
	
	private List<JobDTO> approvalHistory;
	@Autowired 
	private ConferenceSchemeWebService conferenceSchemeWebService;
	
	@Autowired
	private TaskManagementWebService taskManagementWebService;
	
	@Autowired
    private JudgeCurrentUndertaker judgeCurrentUndertaker;

	@Autowired
	private UserManagementWebService userManagementWebService;
	@Override
	public String _execute() throws Exception {
	    
	    //判断当前用户和job承办人是否匹配,如果不匹配转到异常页面
        judgeCurrentUndertaker.judgeOperationAuthority(jobId);
        //获取批示人
        List<UserInfoDTO> userInfoDTOs = userManagementWebService.findAllUserInfoHasAccount();
        if(userInfoDTOs!=null && userInfoDTOs.size()!=0){
            userInfoString=JSONArray.fromObject(userInfoDTOs).toString().replace("\"", "\\\"");
        }
        //审批记录
        approvalHistory = conferenceSchemeWebService.findFinishedSchemeApprovalHistoryRecordByJobId(jobId);
        
		JobDTO nowJob = taskManagementWebService.findJobDetailByJobId(jobId);
		preSchemeJobDataDTO = conferenceSchemeWebService.findPreConferenceJobDataDTOByJobId(jobId);
		if(preSchemeJobDataDTO != null && preSchemeJobDataDTO.getOnlineDocumentDTO() != null){
			onlinePath = preSchemeJobDataDTO.getOnlineDocumentDTO().getDocumentPath();
			onlineVersion = preSchemeJobDataDTO.getOnlineDocumentDTO().getDocumentVersion();
		}
		missionDTO = conferenceSchemeWebService.findMissionByJobId(jobId);
		nowJobType = nowJob.getJobType();
		if("方案审批".equals(nowJobType)){//当前JobType为"方案审批"，跳转到审批页面
			return "approve";
		}
		if("方案审批取回".equals(nowJobType) || "方案定稿".equals(nowJobType)){
		    return "getBack";
		}
		return SUCCESS;
	}


	public Long getJobId() {
		return jobId;
	}

	public void setJobId(Long jobId) {
		this.jobId = jobId;
	}

	public SchemeJobDataDTO getPreSchemeJobDataDTO() {
		return preSchemeJobDataDTO;
	}

	public void setPreSchemeJobDataDTO(SchemeJobDataDTO preSchemeJobDataDTO) {
		this.preSchemeJobDataDTO = preSchemeJobDataDTO;
	}

	public String getNowJobType() {
		return nowJobType;
	}

	public void setNowJobType(String nowJobType) {
		this.nowJobType = nowJobType;
	}


	public void setOnlinePath(String onlinePath) {
		this.onlinePath = onlinePath;
	}


	public String getOnlinePath() {
		return onlinePath;
	}


	public void setOnlineVersion(String onlineVersion) {
		this.onlineVersion = onlineVersion;
	}


	public String getOnlineVersion() {
		return onlineVersion;
	}


    public String getUserInfoString() {
        return userInfoString;
    }

    public void setUserInfoString(String userInfoString) {
        this.userInfoString = userInfoString;
    }


    public MissionDTO getMissionDTO() {
        return missionDTO;
    }


    public void setMissionDTO(MissionDTO missionDTO) {
        this.missionDTO = missionDTO;
    }


    public List<JobDTO> getApprovalHistory() {
        return approvalHistory;
    }


    public void setApprovalHistory(List<JobDTO> approvalHistory) {
        this.approvalHistory = approvalHistory;
    }
    
    
}
